/**
 * 手写new
 */

function newO() {
    let newObj = null
    let result = null
    let constructor = Array.prototype.shift.call(arguments)
    // 让构造函数和生成的对象建立联系
    newObj = Object.create(constructor.prototype)
    //修改构造函数的this
    result = constructor.apply(newObj, arguments)
    //返回对象
    let flag = result && (typeof result === "object" || typeof result === "function")
    return flag ? result : newObj
}

let a = newO(Object, {name: 'zhangsan'})
let b = newO(Array, ...[1, 2, 3, 4])
console.log('a', a)
console.log('b', b)
